package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.DrugBean;
import com.hxkcloud.patient.viewholders.DrugListViewHolder;

import java.util.List;

/**
 * Created by william_sun on 2016-10-08.
 * Description:药品列表
 */
public class DrugListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<DrugBean> drugs;
    private LayoutInflater mInflater;
    private onDrugCheckListener listener;

    public DrugListAdapter(Context mContext, List<DrugBean> datas, onDrugCheckListener listener) {
        this.mContext = mContext;
        this.drugs = datas;
        mInflater = LayoutInflater.from(mContext);
        this.listener = listener;
    }

    public void setData(List<DrugBean> datas) {
        this.drugs = datas;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.adapter_druglist, null);
        DrugListViewHolder holder = new DrugListViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
//        holder = (DrugListViewHolder) holder;

        DrugBean drugBean = drugs.get(position);
        ((DrugListViewHolder) holder).tv_drug.setText(drugBean.getDrugName());
       // if (drugBean.isCheck()) {
           // ((DrugListViewHolder) holder).iv_check.setImageResource(R.drawable.drug_check);
     //   } else {
           // ((DrugListViewHolder) holder).iv_check.setImageResource(R.drawable.drug_uncheck);
     //   }
        ((DrugListViewHolder) holder).ll_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onDrugCheck(position);

            }
        });
    }

    @Override
    public int getItemCount() {
        return drugs.size();
    }

    public interface onDrugCheckListener {
        void onDrugCheck(int position);
    }
}
